<template>
  <div class="home">
    <img alt="Vue logo" src="../assets/logo.png">
    <HelloWorld msg="Welcome to Your Vue.js + TypeScript App"/>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import HelloWorld from '@/components/HelloWorld.vue'; // @ is an alias to /src

// 引入登录的方法
import {login} from '@/api/user';

export default defineComponent({
  name: 'HomeView',
  components: {
    HelloWorld,
  },
  async mounted() {
   //调用
   let result = login({
    email: 'super002@qq.com',
    password: '121345678@aA1'
   })
   console.log('mounted调用：',result); 

   //axios 返回promise对象。取里面的数据有两种方式
   //1.then...catch
   result
   .then((res)=>{
    console.log('then调用：',res); //成功时结果
   })
   .catch((err)=>{
    console.log('catch调用：',err); //失败时结果
   })
   
   //2.async...await  
   let res:AxiosResponse = await result;        //await 等待promise对象返回结果(成功时的结果，就是then的)
   console.log('async调用：',res); 

   if(res.code === 0){
    //登录成功
   }else{
    //登录失败
   }
  },
});
</script>
